package vn.orderonline.core.commons.utils;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Calendar;

public class DateUtils extends org.apache.commons.lang.time.DateUtils {

	public static long now() {
		Calendar calendar = Calendar.getInstance(UTC_TIME_ZONE);
		return calendar.getTimeInMillis();
	}
	
	public static Date currentDate() {
		Calendar calendar = Calendar.getInstance(UTC_TIME_ZONE);
		return new Date(calendar.getTimeInMillis());
	}
	
	public static String timestampToString(Timestamp date, String pattern) {
		SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
		return dateFormat.format(date);
	}
	
	public static String dateToString(Date date, String pattern) {
		SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
		return dateFormat.format(date);
	}
	
	public static Date stringToDate(String s, String pattern) {
		SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
		try {
			return dateFormat.parse(s);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
}
